﻿@if (ViewBag.IsPjaxRequest == false)
{
    Layout = "../Shared/__Layout.cshtml";
}
<section class="content-header">
    <h1>
        消息管理
    </h1>

</section>


<section class="content">
    <div class="row">
        <div class="col-md-3">
            <a href="@Url.Action("Create")" data-toggle="ajaxModal" class="btn btn-primary btn-block margin-bottom">发消息</a>

            <div class="box box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">文件夹</h3>

                    <div class="box-tools">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse">
                            <i class="fa fa-minus"></i>
                        
                        </button>
                    </div>
                </div>
                <div class="box-body no-padding">
                    <ul class="nav nav-pills nav-stacked" id="boxes" >
                        <li class="active">
                            <a href="javascript:void(0)" onclick="new message().inBox(this);">
                                <i class="fa fa-inbox"></i> 收件箱
                                <input type="hidden" />
                            </a>
                        </li>
                        <li><a href="javascript:void(0)" onclick="new message().outBox(this);"><i class="fa fa-envelope-o"></i> 发件箱</a></li>
                        <li><a href="javascript:void(0)" onclick="new message().draftBox(this);"><i class="fa fa-file-text-o"></i> 草稿箱</a></li>
                        <li><a href="javascript:void(0)" onclick="new message().dustbin(this);"><i class="fa fa-trash-o"></i> 垃圾箱</a></li>
                    </ul>
                </div>
            </div>

            <!-- /.box -->
        </div>
        <!-- /.col -->
        <div class="col-md-9">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <div class="dataTable-tools btn-group">
                        <button type="button" class="btn btn-danger btn-sm" onclick="window.app.deleteItem('dataList','@Url.Action("Delete")')"><i class="fa fa-trash-o"></i> 删除</button>
                        <button type="button" class="btn btn-default btn-sm"><i class="fa fa-reply"></i> 回复</button>
                        <button type="button" class="btn btn-default btn-sm" onclick="window.app.search();"><i class="fa fa-refresh"></i> 刷新</button>
                    </div>
                  
                    <div class="box-tools SearchArea">
                        <div class="input-group input-group-sm" style="width:150px;float:right;">
                            <input type="text" name="Title" class="form-control pull-right" placeholder="">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default" onclick="window.app.search();"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body no-padding">
          
                    <div class="table-responsive">
                        <table id="dataList" class="table table-bordered table-striped table-hover dataTable text-center" width="100%"></table>
                    </div>

                </div>
            </div>
        </div>
    </div>

</section>
<script type="text/javascript">
 
   $('#dataList').dataTable({
            "serverSide": true,
            "ajax": {
                "url": "@Url.Action("GetPaged")",
                "type": "POST"
            },
            "columnDefs": [
                { sDefaultContent: '', aTargets: ['_all'] },
                { "searchable": false, sortable: false, "orderable": false, "targets": [-1, 0, 1, 2] },
                { "sClass": "editableCol", "aTargets": [1] }
            ],
            columns: [
                { title: '<label class="checkbox i-checks"><input type="checkbox" /><i></i></label>', data: function (row, type, set) { return '<label class="checkbox i-checks"><input type="checkbox" name="cellCheckbox" value="' + row.id + '" /><i></i></label>'; }, "bStorable": false, width: 30 },
                { title: "发件人", data: 'senderName',width:100 },
                {
                    title: "标题",
                    data: "content", render: function (data, type, row, meta)  {
                        return '<a data-toggle="ajaxModal" class="auto" href="@Url.Action("Details")/' + row.id + '">' + row.content + '</a>';
                    }
                },
                { "title": "时间", data: "publishTime", render: function (data, type, row, meta) { return moment(row.publishTime).format("MM-DD hh:mm:ss"); }, width: 140, "sClass": "center" }

            ]
        });

 
    var message = function() {
        var self = this;

        self.inBox = function (e) {
            $('#boxes').find("li").removeClass('active');   
            $(e).parent().addClass('active');  
            $('#dataList').DataTable().ajax.url('@Url.Action("GetPaged")');
            $('#dataList').DataTable().ajax.reload();
        }
        self.outBox = function (o) {
            $('#boxes').find("li").removeClass('active');
            $(o).parent().addClass('active');  

            $('#dataList').DataTable().ajax.url('@Url.Action("GetOutboxPaged")');
            $('#dataList').DataTable().ajax.reload();
        }
        self.draftBox = function (e) {
            $('#boxes').find("li").removeClass('active');   
            $(e).parent().addClass('active');  
            $('#dataList').DataTable().ajax.url('@Url.Action("GetDraftboxPaged")');
            $('#dataList').DataTable().ajax.reload();
        }
        self.dustbin = function (e) {
            $('#boxes').find("li").removeClass('active');  
            $(e).parent().addClass('active');  
            $('#dataList').DataTable().ajax.url('@Url.Action("GetDustbinPaged")');
            $('#dataList').DataTable().ajax.reload();
        }
    }
</script>